let pageArr = [5, 6, 7, 8, 9, 10];
let coun = pageArr[0];
// 渲染每页显示条数
// loc是渲染的位置${''},是一个jq对象节点,对应元素最好是li，可以使用boostrap里的下拉菜单；pageArr是渲染条数的数组
window.onload = () => {
    pageArr.forEach(item => {
        $('.dropdown-menu').append(`
                  <li data-num="${item}">
                     <a href="#">每页显示 ${item} 条</a>
                  </li> 
     `)
    })
    $('.dropdown-menu').on('click', 'li', function () {
        coun = parseInt($(this).attr('data-num'));
        showDate();
    });
}
      
let count = 5; //每一页的条数
let page = 1; //当前页

//渲染页面
showData()
function showData() {
    $.ajax({
        url: '/salary/quer',
        data: {
            count: count,
            page: page
        },
        success: (res) => {
            if (res.error) {
                console.log(res.erro);
            } else {
                // 渲染表格
                $('tbody').html('')
                $(res.data).each((index, item) => {
                    $('tbody').append(`
                    <tr data-id="${item.p_id}">
                        <td>${item.p_id}</td>
                        <td>${item.p_number}</td>
                        <td>${item.p_project}</td>
                        <td>${item.p_state}</td>
                        <td>${item.p_type}</td>
                        <td>${item.p_data}</td>
                        <td>${item.p_length}</td>
                        <td>${item.p_precision}</td>
                        <td>${item.p_note}</td>
                        <td>${item.p_founder}</td>
                        <td>${item.p_founderTime}</td>
                        <td>${item.p_update}</td>
                        <td>${item.p_updateTime}</td>
                        <td>${item.p_rules}</td>
                        <td>
                        <button><span class="iconfont icon-pen">编辑</span></button>
                        <button><span class="iconfont icon-lajitong">删除</span></button>
                        </td>
                    </tr>
                    `);
                });
                // 渲染页码
                 $('#myli').html('')
                for (let i = 1; i <= Math.ceil((res.total / count)); i++) {
                    if (page == i) {
                        $('#myli').append(`
                                <a class="active" href="javascript:;">${i}</a>
                                        `)
                    }else{
                        $('#myli').append(`
                        <a href="javascript:;">${i}</a>
                       `)
                    }
                }
            }
        }
    });
};
// showDate();
  // 点击页码
  console.log('12345')
  $('.pagination').on('click', 'a', function () {
    console.log($(this).text());
    page = $(this).text();
    showData();
})

function myFunction() {
    // 声明变量
    var input, filter, table, tr, td, i;
    input = document.getElementById("myInput");
    filter = input.value.toUpperCase();
    table = document.getElementById("myTable");
    tr = table.getElementsByTagName("tr");
  
    // 循环表格每一行，查找匹配项
    for (i = 0; i < tr.length; i++) {
      td = tr[i].getElementsByTagName("td")[0];
      if (td) {
        if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
          tr[i].style.display = "";
        } else {
          tr[i].style.display = "none";
        }
      } 
    }
  }
  
function delOne(customerId){ 
    let sure=window.confirm("确定删除么?");        
     if(sure){             
         window.location.href="${pageContext.request.contextPath}/DelCustomerServlet?customerId="+customerId;    //客户端转向servlet用于删除数据
       }   
}
